//配置axios的全局基本路径
axios.defaults.baseURL='http://localhost:8080'
//给Vue扩展一个属性$http
Vue.prototype.$http=axios;

//1 使用axios前置拦截器，让所有的请求都携带uToken
axios.interceptors.request.use(config=>{
    //携带token
    let token =  localStorage.getItem("token");
    if(token){
        config.headers['token']=token;
    }
    return config;
},error => {
    Promise.reject(error);
})
//==============axios后台拦截器实现后端已经退出登录的跳转登录页面======================//
axios.interceptors.response.use(config=>{
    // console.log(config)
    let data = config.data;
    if(!data.success && "noLogin"===data.message)
    {
        localStorage.removeItem("token");
        localStorage.removeItem("logininfo");
        location.href="/login.html";
    }
    // console.log("========")
    return config;
},error => {
    Promise.reject(error)
})

